package com.example.administrator.myapplication.heart;

import android.app.Application;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.graphics.Color;
import android.os.Bundle;
import android.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.example.administrator.myapplication.BmobApplication;
import com.example.administrator.myapplication.R;


public class heart_main_Fragment extends Fragment {
    private Button btHeartRate;
    private  Button btTimer;
    private Button  bt_heard_submit;
    private BmobApplication heard_apps;
    private Toolbar toolbar;




    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        View view = inflater.inflate(R.layout.fragment_heart_main_, container, false);
        btHeartRate = (Button) view.findViewById(R.id.heart_bt_rate);
        btTimer = (Button) view.findViewById(R.id.heart_bt_time);
        bt_heard_submit= (Button) view.findViewById(R.id.bt_heard_submit);
        heard_apps= (BmobApplication) getActivity().getApplication();

        toolbar = (Toolbar) getActivity().findViewById(R.id.heard_main_toolbar);
        toolbar.setTitle("心肺耐力适能");
        toolbar.setTitleMarginStart(35);
        toolbar.setTitleTextColor(Color.parseColor("#ffffff"));
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });

        btHeartRate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getHeartRateFragment();
            }
        });

        btTimer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getHeartTimerFragment();
            }
        });

        bt_heard_submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    getActivity().finish();
            }
        });
        return view;
    }

    public void getHeartRateFragment() {
        heart_heartrate_Fragment heartRateFragment = new heart_heartrate_Fragment();
        FragmentManager fm = this.getFragmentManager();            //设置fragment管理器
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.fragment_heart, heartRateFragment);      //替换当前的fragment
        ft.commit();
    }

    public void getHeartTimerFragment(){
        heart_timer_Fragment heartTimerFragment = new heart_timer_Fragment();
        FragmentManager fm = this.getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.fragment_heart,heartTimerFragment);
        ft.commit();
    }

}
